package com.thingsgrid.device.monitor.controller;
import com.thingsgrid.device.entity.Device;
import com.thingsgrid.device.entity.PerformanceMetrics;
import com.thingsgrid.device.monitor.service.IPropertyService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import org.springblade.core.tool.api.R;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.LinkedHashMap;
import java.util.List;

/**
 *性能分析
 */
@AllArgsConstructor
@RestController
@RequestMapping("/proerty_classify")
@Api(value = "设备性能分析", tags = "设备性能分析")
public class PropertyAnalyzeController {

	private com.thingsgrid.device.monitor.service.IPropertyService IPropertyService;

	/**
	 *
	 *通过产品Id查询关联的设备
	 * @author 陈学栋
	 * @date 2019/8/20 13:59
	 */
	@PostMapping("/select_device")
	@ApiOperation(value = "通过产品ID查询设备", notes = "通过产品ID查询设备", position =1)
	public R<List<Device>> list(@RequestParam String productId){
		List<Device> deviceList = IPropertyService.findDeviceById(productId);
		return R.data(deviceList);
	}


	/**
	 *
	 *通过Id查询设备指标名称
	 * @author 陈学栋
	 * @date 2019/8/27 10:56
	 */
	@PostMapping("/select_metricsName")
	@ApiOperation(value = "通过Id查询指标名称", notes = "通过Id查询指标名称", position =2)
	public R<List<PerformanceMetrics>> findMetricsName(@RequestParam String productId){
		List<PerformanceMetrics> metricsList = IPropertyService.findMetricsNameById(productId);
		return R.data(metricsList);
	}

	/**
	 *
	 *查询设备的指标
	 * @author 陈学栋
	 * @date 2019/8/20 14:00
	 */
	@PostMapping("/select_index")
	@ApiOperation(value = "查询设备指标", notes = "查询设备指标", position =3)
	public R<LinkedHashMap<String, Double>> selectDeviceCpu(@RequestParam String deviceId, @RequestParam Integer selectTime,@RequestParam String sign){
		LinkedHashMap<String, Double> map = IPropertyService.getDeviceIndex(deviceId,selectTime,sign);
			return R.data(map);
	}
}
